package cn.sym.org.controller;

import cn.sym.basic.query.BaseQuery;
import cn.sym.basic.util.AjaxResult;
import cn.sym.basic.util.PageList;
import cn.sym.org.aspect.anno.Operation;
import cn.sym.org.domain.SystemDictionaryType;
import cn.sym.org.query.DepartmentQuery;
import cn.sym.org.service.ISystemDictionaryTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/DicType")
public class DictionaryTypeController {

    @Autowired
    private ISystemDictionaryTypeService isystemDictionaryTypeService;

    /**
     * 新增和修改
     * @param systemDictionaryType
     * @return
     */
    @PutMapping
    public AjaxResult addAndUpdate(@RequestBody SystemDictionaryType systemDictionaryType){
        try {
            if (systemDictionaryType.getId()==null){
                isystemDictionaryTypeService.add(systemDictionaryType);
            }else{
                isystemDictionaryTypeService.update(systemDictionaryType);
            }
            return new AjaxResult();
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.my().setSuccess(false).setMessage("操作失败！！！");
        }
    }

    /**
     * 单条删除
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable("id") Long id){
        try {
            isystemDictionaryTypeService.remove(id);
            return AjaxResult.my();
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.my().setSuccess(false).setMessage("网络错误，请稍后再试！！1");
        }
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @Operation("批量删除")
    @PatchMapping
    public AjaxResult remove(@RequestBody List<Long> ids){
        try {
            isystemDictionaryTypeService.removeMore(ids);
            return AjaxResult.my();
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.my().setSuccess(false).setMessage("网络错误，请稍后再试！！1");
        }
    }
    /**
     * 通过id查询
     */
    @GetMapping("/{id}")
    public SystemDictionaryType queryById(@PathVariable("id") Long id){
        return isystemDictionaryTypeService.queryById(id);
    }
    /**
     * 查询所有
     */
    @GetMapping
    public List<SystemDictionaryType> queryAll(){
        System.out.println("哈哈哈哈哈!!!!!");
        return isystemDictionaryTypeService.queryAll();
    }
    /**
     * 查询无限极部门树
     * @return
     */
   /* @GetMapping("/tree")
    public List<SystemDictionaryType> queryTree(){
        return isystemDictionaryTypeService.queryTree();
    }*/
    /**
     * 高级查询
     */
    @PostMapping
    public PageList<SystemDictionaryType> queryPage(@RequestBody BaseQuery query){
        return isystemDictionaryTypeService.queryPage(query);
    }
}
